<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> 
<title>录入航班信息</title>
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>	
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

$(function(){
	$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	initData();
	
	var msg="${msg}"||"";
	if(msg!="" && msg=="success"){
		alert("操作成功！");
	}else if(msg!=""){
		alert(msg);
	}
	
});

function initData(){
	var date=new Date();
	var year=date.getFullYear();
	var month=date.getMonth()+1;
	month=(month<10?"0"+month:""+month);
	var d=date.getDate();
	d=(d<10?"0"+d:""+d);
	var hour=date.getHours();
	var minute=date.getMinutes();
	minute=(minute<10?"0"+minute:""+minute);
	var str1=year+"-"+month+"-"+d;
	var str2=hour+":"+minute;
	$("#flightBatchStartDate").val(str1);
	$("#flightBatchEndDate").val(str1);
	$("#flightBatchStartTime").val("00:00");
	$("#flightBatchEndTime").val("00:00");
}



function validateAll(){
	var url="<%=request.getContextPath()%>/luruhangbanAction!saveHangban.action";
	var flag=  validateCompany() && 
			validateCity() && 
			validateFlightNo()&&
			validateTime() && 
			validatePrice();
	if(flag==true){
		FDCWait.show();
		$.ajax({
            cache: false,
            type: "POST",
            url:url,
            dataType:"html",
            data:$('#luruForm').serialize(),
            async: false,
            error: function(request) {
                alert("连接失败！请联系管理员");
            },
            success: function(data) {
            	if(data=="success"){
            		alert("数据保存成功！");
            	}else{
            		alert("数据保存失败！");
            	}
                
            },
            complete:function(){
            	FDCWait.hide();
            }
        });
		
		
	}	
}


function changeCompany(){
	var op=$("#company").find("option:selected")[0];
	var carrierKey=op.id;
	changeCompany._ck=carrierKey||"";
}

function validateCompany(){
	var val=$("#company").val();
	if(val==""){
		alert("请选择航空公司");
		return false;
	}
	return true;
}

function validateFlightNo(){
	var val=$("#planeInfoNo").val();
	
	if(changeCompany._ck==""){
		alert("请先确定航空公司");
		return false;
	}
	if(val.indexOf(changeCompany._ck)!=0){
		alert("您选择的是【"+$("#company").find("option:selected").text()+"】航空公司\n航班号请以【"+changeCompany._ck+"】开头");
		return false;
	}
	return true;
}

function validateCity(){
	var form=$.trim($("#depCity").val());
	var to=$.trim($("#arrCity").val());
	if(form==""||form=="中文/拼音"){
		alert("【出发城市】不能为空");
		return false;
	}
	if(to==""||to=="中文/拼音"){
		alert("【到达城市】不能为空");
		return false;
	}
	if(form==to){
		alert("【出发城市】 和 【到达城市】 不能相同");
		return false;
	}
	return true;
}

function validateTime(){
	if($.trim($("#flightBatchStartDate").val())=="" || $.trim($("#flightBatchStartTime").val())==""){
		alert("请选择起飞时间");
		return false;
	}
	if($.trim($("#flightBatchEndDate").val())=="" || $.trim($("#flightBatchEndTime").val())==""){
		alert("请选择到达时间");
		return false;
	}
	var startDate=($("#flightBatchStartDate").val()+" "+$("#flightBatchStartTime").val()+":00").replace(/-/g,"/");
	var endDate=($("#flightBatchEndDate").val()+" "+$("#flightBatchEndTime").val()+":00").replace(/-/g,"/");
	var start=new Date(startDate);
	var end=new Date(endDate);
	if(start.getTime()==end.getTime()){
		alert("起飞时间和到达时间不能完全相同");
		return false;
	}else if(end.getTime()<start.getTime()){
		alert("到达时间必须大于起飞时间");
		return false;
	}
	return true;
}

function validatePrice(){
	var reg=/^[1-9](\d*|\d*\.\d{1,2})$/;//小数点后两位
	var low=$("#lowprPrice").val();
	var hig=$("#highPrice").val();
	if(!reg.test(low)){
		alert("【最低价格】为数字格式，可以到小数点后两位");
		$("#lowprPrice").focus();
		return false;
	}
	if(!reg.test(hig)){
		alert("【最高价格】为数字格式，可以到小数点后两位");
		$("#highPrice").focus();
		return false;
	}
	hig=parseFloat(hig);
	low=parseFloat(low);
	if(hig<low){
		alert("【最高价格】不能低于【最低价格】");
		return false;
	}
	return true;
}

</script>

</head>
<body style="height:650px;">

<div class="main main_max minhgt450" >
<div class="form_table_tltle">录入航班信息</div>
<form action="<%=request.getContextPath()%>/luruhangbanAction!saveHangban.action" method="post" id="luruForm">
<table cellSpacing=0 cellPadding=0 width="100%" border=0 class="form_table">
	<tr>
		<td class="left">航空公司：</td>
		<td class="" style="width:400px;">
			<select id="company" name="company" style="" onchange="changeCompany();">
				<option value=""> --请选择-- </option>
				<c:if test="${sourceList != null}">
					<c:forEach var='item' items="${sourceList }">
					<option value="${item.name}" id="${item.carrierKey }">${item.name}</option>
					</c:forEach>
				</c:if>
			</select>
		</td>
		<td class="left"></td>
		<td class=""></td>
	<tr>
	<tr>
		<td class="left">航线：</td>
		<td class="">
				<!-- <input type="text" readonly="readonly" id="depCity" name="depCity"/>&nbsp;至&nbsp;
					 <input type="text" readonly="readonly" id="arrCity" name="arrCity"/> -->
					 <jsp:include page="../inc/flightSelect.jsp">
	    <jsp:param value="${fromCity}" name="fromCity"/>
	    <jsp:param value="${fromCityCode}" name="fromCityCode"/>
	    <jsp:param value="${toCity}" name="toCity"/>
	    <jsp:param value="${toCityCode}" name="toCityCode"/>
 </jsp:include>
		</td>
		<td class="left"></td>
		<td class=""></td>
	<tr>
	<tr>
		<td class="left">航班号</td>
		<td class=""><input type="text" id="planeInfoNo" name="planeInfoNo"/></td>
		<td class="left"></td>
		<td class=""></td>
	</tr>
	<tr>
		<td class="left">起飞日期</td>
		<td class=""><input type="text" readonly="readonly"  id="flightBatchStartDate" name="flightBatchStartDate"
		onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d'});"
		
		/></td>
		<td class="left">起飞时间</td>
		<td class=""><input type="text" readonly="readonly" id="flightBatchStartTime" name="flightBatchStartTime"
		onfocus="WdatePicker({dateFmt:'HH:mm',minDate:'00:00',maxDate:'23:59'})"
		/></td>
	<tr>
	<tr>
		<td class="left">预计到达日期</td>
		<td class=""><input type="text" readonly="readonly" id="flightBatchEndDate" name="flightBatchEndDate"
		onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'flightBatchStartDate\')}'});"
		/></td>
		<td class="left">预计到达时间</td>
		<td class=""><input type="text" readonly="readonly" id="flightBatchEndTime" name="flightBatchEndTime"
		onfocus="WdatePicker({dateFmt:'HH:mm',minDate:'00:00',maxDate:'23:59'})"
		/></td>
	</tr>
	
	<tr>
		<td class="left">最低价格</td>
		<td class=""><input type="text" id="lowprPrice" name="lowprPrice"/></td>
		<td class="left">最高价格</td>
		<td class=""><input type="text" id="highPrice" name="highPrice"/></td>
	</tr>
	<tr>
		 <td colspan="4"  style="text-align:center;height:35px;" >
           	<input id="button" value="" class="btn05" type="button" onclick="validateAll()"/>
   			<input type="reset" value="" onclick="" class="btn03"/>
         </td>
	</tr>
<table>
</form>
</div>
</body>
</html>